/*
 *所有关于sh_progress类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*sh_progressService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using Dapper;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System.Linq;
using VOL.AppManager.IRepositories;
using VOL.Core.Extensions;
using VOL.Entity.DomainModels;
using VOL.Entity.新文件夹;

namespace VOL.AppManager.Services
{
    public partial class sh_progressService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly Ish_progressRepository _repository;//访问数据库

        [ActivatorUtilitiesConstructor]
        public sh_progressService(
            Ish_progressRepository dbRepository,
            IHttpContextAccessor httpContextAccessor
            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            //多租户会用到这init代码，其他情况可以不用
            //base.Init(dbRepository);
        }

        public PageGridData<shprogressdto> GetData(shprogressdto options)
        {
            DynamicParameters sqlParams = new DynamicParameters();
            string sql = " select  row_number() OVER () AS idxx,  * from (   select  * from sh_progress  where 1=1 order by sh_time,citydm asc)  t where 1=1  ";
            string sqlcount = "    select  count(1)  from sh_progress where 1=1 ";


            sql += "    limit @pagesize offset (@pageindex-1)*@pagesize  ";
            sqlParams.Add("pageindex", options.pageindex);
            sqlParams.Add("pagesize", options.pagesize);
            var datacount = repository.DapperContext.ExecuteScalar(sqlcount, sqlParams).GetInt();
            var data = repository.DapperContext.QueryList<shprogressdto>(sql, sqlParams).ToList();
            int totalPages = datacount / options.pagesize;
            if (datacount % options.pagesize != 0)
            {
                totalPages++;
            }
            return new PageGridData<shprogressdto> { rows = data, status = 0, total = datacount, summary = new { pagecount = totalPages } };
        }
    }
}
